layui.use(['jquery','upload','layer','laydate'],function () {
    var $ = layui.jquery;
    var upload = layui.upload;
    var layer = layui.layer;
    var laydate = layui.laydate;

    laydate.render({
        elem:"#startDate",
        type:"datetime",
        tigger:"click"
    });

    laydate.render({
        elem:"#expireDate",
        type:"datetime",
        tigger:"click"
    });

    //上传头像
    var uploadInst = upload.render({
        elem: "#upload",
        url: "/upload/uploadFile",
        multiple: true,
        field: "files",
        size:"2M",
        accept: "images",
        before: function (obj) {
            $('#images').show();
        },
        done: function (res, index, upload) {
            var imgAddress = res.data.path;
            //console.log(res.data.path);
            $("#imgAddress").attr("src",imgAddress);
            $("#imgAddress").attr('style','width: 80px;height:80px;border:2px solid black');
        },
        error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }/*, progress: function (n, elem, e) {
            element.progress('demo', n + '%');
            if (n == 100) {
                layer.msg('上传完毕', {icon: 1});
            }
        }*/
    });
});